import axios, { AxiosRequestConfig } from 'axios'

import { IEventListPublishPathListReq, IEventListPublishPathListRes } from '../interface'
import { normalizeReqData } from '../utils'
import './__mock__'

/** 获取所有发布轨迹 */
export const apiGetEventList = async (
  req: IEventListPublishPathListReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IEventListPublishPathListRes> => {
  const data = normalizeReqData(req)
  const searchWords = (data.searchWords?.trim() || undefined)?.split(/\s*\n+\s*/)
  return axios.post(`/tmsapi/event_template/publishPathList`, { ...data, searchWords }, { signal }).then(res => ({
    ...res.$data,
  }))
}
